/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author ChauAnh
 */
@Stateless
public class CandidateProfile implements CandidateProfileLocal {

    ConnectDB conDB = new ConnectDB();
    Connection conn;

    @Override
    public HashMap getCandidateProfile(String user) {
        HashMap CandidateData = new HashMap();
        try {
            conn = conDB.getConnection();
            String strSql = "SELECT * FROM Candidate WHERE username = ?";

            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, user);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                HashMap hm = new HashMap();
                hm.put("username", rs.getString("username").trim());
                hm.put("first_name", rs.getString("first_name").trim());
                hm.put("middle_name", rs.getString("middle_name").trim());
                hm.put("last_name", rs.getString("last_name").trim());
                hm.put("avatar", rs.getString("avatar").trim());
                hm.put("gender", rs.getString("gender").trim());
                hm.put("birthdate", rs.getString("birthdate").trim());
                hm.put("marital_status", rs.getString("marital_status").trim());
                hm.put("height", rs.getString("height"));
                hm.put("country_living_in", rs.getString("country_living_in").trim());
                hm.put("city", rs.getString("city").trim());
                hm.put("contact_number", rs.getString("contact_number").trim());
                hm.put("mother_tongue", rs.getString("mother_tongue").trim());
                hm.put("religion", rs.getString("religion").trim());
                hm.put("caste", rs.getString("caste").trim());
                hm.put("self_features", rs.getString("self_features").trim());
                hm.put("family_details", rs.getString("family_details").trim());
                //Professional
                hm.put("qualification_current_status", rs.getString("qualification_current_status").trim());
                hm.put("working_at", rs.getString("working_at").trim());
                hm.put("designation", rs.getString("designation").trim());
                hm.put("location", rs.getString("location").trim());
                //Likings
                hm.put("hobbies", rs.getString("hobbies").trim());
                hm.put("favorite_music", rs.getString("favorite_music").trim());
                hm.put("movie", rs.getString("movie").trim());
                hm.put("cuisin_es", rs.getString("cuisin_es").trim());
                hm.put("books", rs.getString("books").trim());                
                hm.put("place", rs.getString("place").trim());
                
                CandidateData.put(rs.getString("username").trim(), hm);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, e);
            }
        }

        return CandidateData;
    }
}
